﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace timetableasy.Models
{
    public class RoleRepository
    {
        private TimeTableDBDataContext db = new TimeTableDBDataContext();

        //Query Methods
        public IQueryable<aspnet_Role>FindAllRoles()
        {
            return db.aspnet_Roles;
        }

        public aspnet_Role GetRoleById(string guid)
        {
            Guid id = Guid.Parse(guid);
            return db.aspnet_Roles.SingleOrDefault(r => r.RoleId == id);
        }

        public aspnet_Role GetRoleByName(string name)
        {
            return db.aspnet_Roles.SingleOrDefault(r => r.RoleName == name);
        }

        public Guid GetRoleIdByName(string name)
        {
            return db.aspnet_Roles.SingleOrDefault(r => r.RoleName == name).RoleId;
        }

        //Insert/Delete Methods

        public void Add(aspnet_Role campus)
        {
            db.aspnet_Roles.InsertOnSubmit(campus);
        }

        public void Delete(aspnet_Role campus)
        {
            db.aspnet_Roles.DeleteOnSubmit(campus);
        }

        //Persistence

        public void Save()
        {
            db.SubmitChanges();
        }
    }
}